<?php
namespace Common\Model;
use Common\Model\AiModel;
class AreaModel extends AiModel {
	
	function getAreaName($id) {
		$name = $this->where(array('id' => $id))->getField('name');
		return $name;
	}
	#载入地址数据
    public function ToPidGetArea($id = 0)
    {
        $data = (D('Area')->where('pid=' . $id)->order('ord DESC,name ASC')->select()); #rs2select
        echo json_encode($data);
        exit;
    }
      //通过省市区汉字来转换成对应的id 辽宁-丹东-东港
   function toFontGetAreaIdArray($font){
     $array=explode("-",$font);
     $whereo['name']=array('like','%'.assoc_substr($array[0],2).'%');
     $areao=$this->where($whereo)->find();

     $wheret['name']=array('like','%'.assoc_substr($array[1],2).'%');
     $wheret['pid'] =$areao['id'];
     $areat=$this->where($wheret)->find();

     $wheres['name']=array('like','%'.assoc_substr($array[2],2).'%');
     $wheres['pid'] =$areat['id'];
     $areas=$this->where($wheres)->find();
     
     $datarea['pro'] =$areao['id'];
     $datarea['city']=$areat['id'];
     $datarea['area']=$areas['id'];
     return $datarea;
   }
   //通过area id string 获取用户的 汉字  辽宁-丹东-东港
   function toUidGetAddressFont($font){
     $arrayArea=explode("-", $font);
     $fontnew='';
     foreach ($arrayArea as $key => $value) {
     	$where['id']=$value;
     	$areaname=$this->where($where)->find();
     	$fontnew[$key]=$areaname['name'];
     }
     return $fontnew;
   }
	
}